//
//  CYRetweetStatusView.swift
//  WeiBo
//
//  Created by Mr_J on 16/3/11.
//  Copyright © 2016年 mac. All rights reserved.
//

import UIKit
import SnapKit

class CYRetweetStatusView: UIView {

    var bottomConstaint: Constraint?
    
    
    var statusViewModel: CYStatusViewModel? {
        didSet{
            contentLabel.text = statusViewModel?.retweetedText
            
            self.bottomConstaint?.uninstall()
            
            if let urls = statusViewModel?.status?.retweeted_status?.pic_urls where urls.count > 0 {
                pictureView.picUrls = urls
                
                pictureView.hidden = false
                
                self.snp_makeConstraints(closure: { (make) -> Void in
                    self.bottomConstaint = make.bottom.equalTo(pictureView).offset(CYStatusCellMargin).constraint
                })
            }else {
                pictureView.hidden = true
                
                self.snp_makeConstraints(closure: { (make) -> Void in
                    self.bottomConstaint = make.bottom.equalTo(contentLabel).offset(CYStatusCellMargin).constraint
                })
            }
            
        }
    }
    
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()   
        
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI() {
        
        backgroundColor = UIColor(white: 239/255, alpha: 1)
        
        addSubview(contentLabel)
        addSubview(pictureView)
        
        contentLabel.snp_makeConstraints { (make) -> Void in
            make.leading.top.equalTo(self).offset(CYStatusCellMargin)
            make.trailing.equalTo(self).offset(-CYStatusCellMargin)
        }
        
        pictureView.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(contentLabel)
            make.top.equalTo(contentLabel.snp_bottom).offset(CYStatusCellMargin)
        }
        
        
        self.snp_makeConstraints { (make) -> Void in
          self.bottomConstaint = make.bottom.equalTo(pictureView).offset(CYStatusCellMargin).constraint
        }
        
        
    }
    
    private lazy var contentLabel: UILabel = {
       
        let label = UILabel(textColor: UIColor.darkGrayColor(), fontSize: 15)
        
        label.numberOfLines = 0

        label.text = "哈哈哈哈啊哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈"
        
        return label
        
    }()
    
    private lazy var pictureView: CYStatusPictureView = CYStatusPictureView(frame: CGRectZero, collectionViewLayout: UICollectionViewFlowLayout())
    
    
    
    
}
